<%@page import="com.iflysse.bbs.dao.impl.UserDaoImpl"%>
<%@page import="com.iflysse.bbs.dao.UserDao"%>
<%@page import="com.iflysse.bbs.model.UserInfo"%>
<%@page import="org.apache.catalina.User"%>
<%@ include file="base.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String account = request.getParameter("account") == null ? null
			: request.getParameter("account").toString();
	String name = request.getParameter("name") == null ? null : request
			.getParameter("name").toString();
	String password = request.getParameter("password") == null ? null
			: request.getParameter("password").toString();
	String email = request.getParameter("email") == null ? null
			: request.getParameter("email").toString();
	
	UserInfo user = new UserInfo();
	user.setAccount(account);
	user.setName(name);
	user.setPassword(password);
	user.setEmail(email);
	
	UserDao userDao = new UserDaoImpl();
	boolean flag = userDao.add(user);
	if(flag){
		String script = "<script>alert('恭喜，注册成功，请在主页中登录...');window.location.href='" + baseUrl + "index_handler.jsp'</script>";
		out.print(script);		
	}else{
		request.setAttribute("regMsg", "保存失败，请确认");
		request.getRequestDispatcher("/pages/register.jsp").forward(request, response);
	}
%>